Skip to content

feat(anvil): add block context overrides for eth_call and eth_estimateGas #10487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2025

Conversation

mablr
Copy link
Contributor

@mablr mablr commented May 9, 2025

Motivation

Resolve #10458 by implementing block context overrides for eth_call and eth_estimateGas RPC methods, allowing users to specify block parameters like timestamp, number, difficulty, etc. for call execution context.

Solution

Key changes:

  • BlockOverrides added to EthRequest enum variants for eth_call and eth_estimateGas
  • Block overrides handling implemented in anvil::eth::backend::mem::state as apply_block_overrides() function (ported from reth)
  • Add new error type EvmOverrideError to group state and block override related errors (due to fork mode)
  • State override handling refactored:
    • Rename apply_cached_db_state_override() to apply_state_overrides()
    • Modify to take mutable CacheDB reference instead of creating new instance
    • Consistent pattern for apply_state_overrides() and apply_block_overrides()

PR Checklist

  • Fix EthRequest unfulfilled lint expectation
  • Add Tests with State and Block overrides for eth_call and eth_estimateGas

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great already,

I have a few style nits

@mablr
Copy link
Contributor Author

mablr commented May 10, 2025

Thanks @mattsse for your feedback!
I'm going to commit asap the requested modifications.

I will squash it before marking this PR as ready.

@mablr mablr force-pushed the feature/anvil-block-overrides branch from fb16804 to 5590414 Compare May 11, 2025 20:48
…eGas

This commit implements block context overrides for eth_call and eth_estimateGas RPC methods,
allowing users to specify block parameters like timestamp, number, difficulty, etc. for call
execution context.

Key changes:
- BlockOverrides added to EthRequest enum variants for eth_call and eth_estimateGas
- Block overrides handling implemented in `anvil::eth::backend::mem::state` as `apply_block_overrides()` function (ported from reth)
- Add new error type EvmOverrideError to group state and block override related errors (due to fork mode)
- State override handling refactored:
  - Rename `apply_cached_db_state_override()` to `apply_state_overrides()`
  - Modify to take mutable `CacheDB` reference instead of creating new instance
  - Consistent pattern for `apply_state_overrides()` and `apply_block_overrides()`
@mablr mablr force-pushed the feature/anvil-block-overrides branch from 5590414 to 180f897 Compare May 11, 2025 20:54
@mablr mablr marked this pull request as ready for review May 11, 2025 20:55
mattsse
mattsse previously approved these changes May 16, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, ty!

this will likely conflict with #10454

so I'm resolving the conflicts after and merge this,

tysm

@mattsse mattsse added the T-blocked Type: blocked label May 16, 2025
@mattsse mattsse moved this to Blocked in Foundry May 16, 2025
@zerosnacks zerosnacks self-assigned this May 20, 2025
@zerosnacks zerosnacks removed the T-blocked Type: blocked label May 20, 2025
@zerosnacks zerosnacks moved this from Blocked to In Progress in Foundry May 20, 2025
@zerosnacks zerosnacks added this to the v1.3.0 milestone May 20, 2025
@zerosnacks zerosnacks requested a review from mattsse May 20, 2025 10:14
@zerosnacks zerosnacks moved this from In Progress to Ready For Review in Foundry May 20, 2025
@@ -1143,7 +1144,7 @@ async fn test_estimate_gas() {

// Estimate gas with state override implying sufficient funds.
let gas_estimate = api
.estimate_gas(WithOtherFields::new(tx), None, Some(state_override))
.estimate_gas(WithOtherFields::new(tx), None, EvmOverrides::new(Some(state_override), None))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case for BlockOverrides as well, otherwise lgtm!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quickly added a block number override test case

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

@@ -1143,7 +1144,7 @@ async fn test_estimate_gas() {

// Estimate gas with state override implying sufficient funds.
let gas_estimate = api
.estimate_gas(WithOtherFields::new(tx), None, Some(state_override))
.estimate_gas(WithOtherFields::new(tx), None, EvmOverrides::new(Some(state_override), None))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quickly added a block number override test case

@zerosnacks zerosnacks enabled auto-merge (squash) May 21, 2025 15:38
@zerosnacks zerosnacks merged commit 7b6a9f3 into foundry-rs:master May 21, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry May 21, 2025
@zerosnacks zerosnacks moved this from Done to Completed in Foundry May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(anvil): add eth_call block overrides (like geth)
4 participants